<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"adoontheway.gitee.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="Next.js 学习笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="每天进步一点点032 - Next.js学习">
<meta property="og:url" content="https://adoontheway.gitee.io/2023/05/17/everydayprogress032/index.html">
<meta property="og:site_name" content="Ados">
<meta property="og:description" content="Next.js 学习笔记">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-05-17T02:25:06.000Z">
<meta property="article:modified_time" content="2023-05-17T05:36:41.335Z">
<meta property="article:author" content="ado">
<meta property="article:tag" content="Node">
<meta property="article:tag" content="React">
<meta property="article:tag" content="Next.js">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://adoontheway.gitee.io/2023/05/17/everydayprogress032/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>每天进步一点点032 - Next.js学习 | Ados</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Ados</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">a fullstack game worker</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/adoontheway" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="external nofollow noopener noreferrer" target="_blank"><svg width="80" height="80" viewbox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://adoontheway.gitee.io/2023/05/17/everydayprogress032/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="ado">
      <meta itemprop="description" content="me, robot.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Ados">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          每天进步一点点032 - Next.js学习
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2023-05-17 10:25:06 / 修改时间：13:36:41" itemprop="dateCreated datePublished" datetime="2023-05-17T10:25:06+08:00">2023-05-17</time>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
            <div class="post-description">Next.js 学习笔记</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h1><p>被迫向生活妥协，哪有什么鬼的生活与远方，能找到工作就不错了，操蛋的人生。</p>
<h1 id="Contents"><a href="#Contents" class="headerlink" title="Contents"></a>Contents</h1><p>不用国内的文档，问题太多了。</p>
<h2 id="创建项目"><a href="#创建项目" class="headerlink" title="创建项目"></a>创建项目</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npx create-next-app@latest</span><br></pre></td></tr></table></figure>
<p>之后 <code>npm run dev</code> 就可以看到效果。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&quot;scripts&quot;: &#123;</span><br><span class="line">    &quot;dev&quot;: &quot;next dev&quot;,//应用以开发模式启动</span><br><span class="line">    &quot;build&quot;: &quot;next build&quot;,//应用打包生产环境</span><br><span class="line">    &quot;start&quot;: &quot;next start&quot;,//启动一个生产环境服务器</span><br><span class="line">    &quot;lint&quot;: &quot;next lint&quot;//设置NextJs内置的ESLint配置</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h3 id="新建项目的一些说明"><a href="#新建项目的一些说明" class="headerlink" title="新建项目的一些说明"></a>新建项目的一些说明</h3><ul>
<li>app/page.tsx : 类似主页</li>
<li>app/layout.tsx : 所有页面的根容器，这个页面没有写的话，会在 <code>npm run dev</code> 的时候自动生成</li>
<li>public : 这里用于存放静态资源的，如，图片，字体等。 在代码中可以直接以 <code>/</code> 前缀访问</li>
</ul>
<h2 id="一些原则"><a href="#一些原则" class="headerlink" title="一些原则"></a>一些原则</h2><h3 id="服务端组件与客户端组件之间的传值"><a href="#服务端组件与客户端组件之间的传值" class="headerlink" title="服务端组件与客户端组件之间的传值"></a>服务端组件与客户端组件之间的传值</h3><p>服务端组件与客户端组件之间的值传递需要序列化。也就是函数，日期这样的对象不能直接传给客户端组件。</p>
<h3 id="仅限服务端的代码不要和客户端组件混到一起，这个是很致命的"><a href="#仅限服务端的代码不要和客户端组件混到一起，这个是很致命的" class="headerlink" title="仅限服务端的代码不要和客户端组件混到一起，这个是很致命的"></a>仅限服务端的代码不要和客户端组件混到一起，这个是很致命的</h3><p>可以使用 <em>server-only</em> 包给开发者报错。 <code>cnpm i server-only</code>，然后到仅限服务端的代码中导入即可。</p>
<h3 id="数据获取"><a href="#数据获取" class="headerlink" title="数据获取"></a>数据获取</h3><p>虽然客户端组件也可以获取数据，建议是通过服务端组件获取数据，除非特殊原因。服务端组件获取数据更快更方便。</p>
<h3 id="第三方组件"><a href="#第三方组件" class="headerlink" title="第三方组件"></a>第三方组件</h3><p>服务端组件是一个新的概念，所以生态系统跟不上。很多组件 <code>use client</code> 没有指令会导致在服务端组件中使用的时候会报错。这个时候需要我们自己在本地封装一下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&#x27;use client&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; AcmeCarousel &#125; <span class="keyword">from</span> <span class="string">&#x27;acme-carousel&#x27;</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> AcmeCarousel;</span><br></pre></td></tr></table></figure>
<p>并不是所有的三方组件都需要封装一下，有一个例外是 <em>provider</em> 组件，因为他们只依赖React state和context，通常他们用在应用的root处。</p>
<h3 id="Context"><a href="#Context" class="headerlink" title="Context"></a>Context</h3><p>大部分的React应用依赖 <em>context</em> 在组件之间共享数据，或者直接通过 <em>createContext*，或者通过第三方库 *provider</em> 导入。<br>从 <em>Next.js</em> 13开始， 客户端组件全面支持 <em>context*， 但是不能直接在服务端组件中创建或者消费。这是因为服务端组件没有 React state，因为他们不能交互，<br>*context</em> 主要用于渲染完成后渲染树下的交互组件。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&#x27;use client&#x27;</span>;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">import</span> &#123; createContext, useContext, useState &#125; <span class="keyword">from</span> <span class="string">&#x27;react&#x27;</span>;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">const</span> SidebarContext = createContext();</span><br><span class="line"> </span><br><span class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">Sidebar</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">const</span> [isOpen, setIsOpen] = useState();</span><br><span class="line"> </span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    &lt;SidebarContext.Provider value=&#123;&#123; isOpen &#125;&#125;&gt;</span><br><span class="line">      &lt;SidebarNav /&gt;</span><br><span class="line">    &lt;/SidebarContext.Provider&gt;</span><br><span class="line">  );</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">SidebarNav</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">let</span> &#123; isOpen &#125; = useContext(SidebarContext);</span><br><span class="line"> </span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    &lt;div&gt;</span><br><span class="line">      &lt;p&gt;Home&lt;/p&gt;</span><br><span class="line"> </span><br><span class="line">      &#123;isOpen &amp;&amp; <span class="xml"><span class="tag">&lt;<span class="name">Subnav</span> /&gt;</span></span>&#125;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">  );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>在 <em>root</em> 中创建 <em>context</em> 会导致报错。</li>
<li><em>context</em> 的 <em>provider</em> 一般会在 <strong>root</strong> 附近创建，这样依赖可以提供全局支持。</li>
</ul>
<h3 id="服务端组件间共享数据"><a href="#服务端组件间共享数据" class="headerlink" title="服务端组件间共享数据"></a>服务端组件间共享数据</h3><p>服务端组件不支持React。那么可以通过js自身的一些能力来做数据共享，如单例。<br>请求结果数据的共享是不必要的耦合。</p>
<h2 id="路由"><a href="#路由" class="headerlink" title="路由"></a>路由</h2><p>一般 <em>app</em> 底下的都是服务端组件。</p>
<h3 id="路由约定"><a href="#路由约定" class="headerlink" title="路由约定"></a>路由约定</h3><ul>
<li>文件夹用于定义路由</li>
<li>叶子文件夹中包含了 <em>page.js</em> 用于定义UI<h3 id="文件约定"><a href="#文件约定" class="headerlink" title="文件约定"></a>文件约定</h3>客户端路由包含的文件：</li>
<li>page.js : 定义路由的UI，并且使次路由可公开访问<ul>
<li>route.js : 创建路由的服务端api端点</li>
</ul>
</li>
<li>layout.js : 为一个 <em>segment</em> 和它的子元素创建共享 <strong>UI</strong> 。一个 <em>layout</em> 包装了一个页面和他的子集。<ul>
<li>template.js : 和 <em>layout.js</em> 类似, 他会为导航中的每个字元素创建一个新的实例，这意味着state不会保留，每次都是重新创建。除非你需要这个特性，否则直接使用layout。</li>
</ul>
</li>
<li>loading.js :</li>
<li>error.js :<ul>
<li>global-error.js : </li>
</ul>
</li>
<li>not-found.js<br>当然，也可以添加其他文件，如css，测试用例，组件等等</li>
</ul>
<h3 id="利用客户端导航的服务端路由"><a href="#利用客户端导航的服务端路由" class="headerlink" title="利用客户端导航的服务端路由"></a>利用客户端导航的服务端路由</h3><p>服务端组件和客户端组件不一样。</p>
<h3 id="部分渲染"><a href="#部分渲染" class="headerlink" title="部分渲染"></a>部分渲染</h3><p>兄弟路由之间导航的时候，Next.js只渲染路由变动的部分，不会重新渲染整个也看。</p>
<h3 id="高级路由"><a href="#高级路由" class="headerlink" title="高级路由"></a>高级路由</h3><ul>
<li>平行路由 : 一次展示多个页面，多用于仪表盘</li>
<li>拦截路由 : </li>
</ul>
<h3 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改<head></head></h3><p>可以通过内置的<strong>SEO支持</strong>，在 <em>app</em> 文件夹下面修改 <code>&lt;head&gt;</code> 元素，如 <em>title<em>，</em>meta</em></p>
<h3 id="路由之间的导航方法"><a href="#路由之间的导航方法" class="headerlink" title="路由之间的导航方法"></a>路由之间的导航方法</h3><ul>
<li>Link 组件， 需要href属性</li>
<li>useRouter 钩子</li>
</ul>
<h4 id="Link"><a href="#Link" class="headerlink" title="Link"></a>Link</h4><p>可以使用<code>usePathname()</code> 来判断链接是否是激活状态。</p>
<p>方式滚动到顶部</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;Link href=<span class="string">&quot;/#hashid&quot;</span> scroll=&#123;<span class="literal">false</span>&#125;&gt;</span><br><span class="line">  Scroll to specific id.</span><br><span class="line">&lt;/Link&gt;</span><br></pre></td></tr></table></figure>
<h4 id="useRouter"><a href="#useRouter" class="headerlink" title="useRouter"></a>useRouter</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&#x27;use client&#x27;</span>;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">import</span> &#123; useRouter &#125; <span class="keyword">from</span> <span class="string">&#x27;next/navigation&#x27;</span>;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="function"><span class="keyword">function</span> <span class="title">Page</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">const</span> router = useRouter();</span><br><span class="line"> </span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    &lt;button type=<span class="string">&quot;button&quot;</span> onClick=&#123;<span class="function">() =&gt;</span> router.push(<span class="string">&#x27;/dashboard&#x27;</span>)&#125;&gt;</span><br><span class="line">      Dashboard</span><br><span class="line">    &lt;/button&gt;</span><br><span class="line">  );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>无特殊要求可以直接用 <em>link</em> 组件。</p>
<h2 id="一些概念"><a href="#一些概念" class="headerlink" title="一些概念"></a>一些概念</h2><h3 id="Server-Component-Vs-Client-Component"><a href="#Server-Component-Vs-Client-Component" class="headerlink" title="Server Component Vs Client Component"></a>Server Component Vs Client Component</h3><p>服务端组件只在服务端渲染，可以在页面初始化的时候提速；客户端组件优先在客户端渲染，但是服务端也可以进行预渲染然后在客户端合成。<br><code>&#39;use client&#39;</code> 必须定义在第一行，所有import之前，模组里面只要在入口点定义一次就可以了，然后在模组里面导入的其他组件都将被视为客户端组件。<br>|场景|Server Component| Client Component |<br>|—-|—-|—-|<br>| 获取数据 | ✅ | ❎ |<br>| 访问后端资源 | ✅ | ❎ |<br>| 敏感数据保存在服务端（访问token，api key等等） | ✅ | ❎ |<br>| 将大型依赖保存在服务端/减少客户端js | ✅ | ❎ |<br>| 添加互动与事件监听 例如：onClick，onChange 等 | ❎ | ✅ |<br>| useState和生命周期effect : useState,useReducer,useEffect等 | ❎ | ✅ |<br>| 使用仅浏览器支持的api | ❎ | ✅ |<br>| 使用基于state，effect或者仅支持浏览器api的自定义钩子 | ❎ | ✅ |<br>| 使用React Class Component | ❎ | ✅ |</p>
<h4 id="组合使用的渲染流程"><a href="#组合使用的渲染流程" class="headerlink" title="组合使用的渲染流程"></a>组合使用的渲染流程</h4><ul>
<li>服务端在将渲染结果发送到客户端之前渲染所有的服务端组件<ul>
<li>包括了客户端组件内嵌的服务端组件</li>
<li>遇到客户端组件就跳过</li>
</ul>
</li>
<li>在客户端React渲染服务端返回的服务端组件渲染后的结果中的客户端组件和插槽<ul>
<li>如果客户端组件中嵌入了任何服务端组件，他们的渲染内容会正确的渲染到客户端组件中</li>
</ul>
</li>
</ul>
<p><em>Next.js</em> 在初始页面加载期间，会将以上组件渲染结果提前备服务端预渲染成html，以使页面加载更快。<br>在服务端渲染组件中的子客户端组件中，可以直接插入服务端组件。</p>
<p>鉴于以上流程，在客户端组件中导入服务端组件有一些限制：</p>
<blockquote>
<p>不能直接导入服务端组件，建议通过props的方式传入</p>
</blockquote>
<h1 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h1><ul>
<li><a target="_blank" rel="external nofollow noopener noreferrer" href="https://nextjs.org/docs/getting-started/installation">官方文档</a></li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Node/" rel="tag"># Node</a>
              <a href="/tags/React/" rel="tag"># React</a>
              <a href="/tags/Next-js/" rel="tag"># Next.js</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2023/04/04/everydayprogress033/" rel="prev" title="每天进步一点点033 - 搭一下 Stable Diffusion WebUI">
      <i class="fa fa-chevron-left"></i> 每天进步一点点033 - 搭一下 Stable Diffusion WebUI
    </a></div>
      <div class="post-nav-item">
    <a href="/2023/09/12/everydayprogress034/" rel="next" title="每天进步一点点034 - tensorflow 在arm架构上的使用">
      每天进步一点点034 - tensorflow 在arm架构上的使用 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Preface"><span class="nav-number">1.</span> <span class="nav-text">Preface</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Contents"><span class="nav-number">2.</span> <span class="nav-text">Contents</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E9%A1%B9%E7%9B%AE"><span class="nav-number">2.1.</span> <span class="nav-text">创建项目</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%B0%E5%BB%BA%E9%A1%B9%E7%9B%AE%E7%9A%84%E4%B8%80%E4%BA%9B%E8%AF%B4%E6%98%8E"><span class="nav-number">2.1.1.</span> <span class="nav-text">新建项目的一些说明</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%80%E4%BA%9B%E5%8E%9F%E5%88%99"><span class="nav-number">2.2.</span> <span class="nav-text">一些原则</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%BB%84%E4%BB%B6%E4%B8%8E%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%BB%84%E4%BB%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E4%BC%A0%E5%80%BC"><span class="nav-number">2.2.1.</span> <span class="nav-text">服务端组件与客户端组件之间的传值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%85%E9%99%90%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%9A%84%E4%BB%A3%E7%A0%81%E4%B8%8D%E8%A6%81%E5%92%8C%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%BB%84%E4%BB%B6%E6%B7%B7%E5%88%B0%E4%B8%80%E8%B5%B7%EF%BC%8C%E8%BF%99%E4%B8%AA%E6%98%AF%E5%BE%88%E8%87%B4%E5%91%BD%E7%9A%84"><span class="nav-number">2.2.2.</span> <span class="nav-text">仅限服务端的代码不要和客户端组件混到一起，这个是很致命的</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E8%8E%B7%E5%8F%96"><span class="nav-number">2.2.3.</span> <span class="nav-text">数据获取</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%AC%AC%E4%B8%89%E6%96%B9%E7%BB%84%E4%BB%B6"><span class="nav-number">2.2.4.</span> <span class="nav-text">第三方组件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Context"><span class="nav-number">2.2.5.</span> <span class="nav-text">Context</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%BB%84%E4%BB%B6%E9%97%B4%E5%85%B1%E4%BA%AB%E6%95%B0%E6%8D%AE"><span class="nav-number">2.2.6.</span> <span class="nav-text">服务端组件间共享数据</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%B7%AF%E7%94%B1"><span class="nav-number">2.3.</span> <span class="nav-text">路由</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%B7%AF%E7%94%B1%E7%BA%A6%E5%AE%9A"><span class="nav-number">2.3.1.</span> <span class="nav-text">路由约定</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E7%BA%A6%E5%AE%9A"><span class="nav-number">2.3.2.</span> <span class="nav-text">文件约定</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A9%E7%94%A8%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%AF%BC%E8%88%AA%E7%9A%84%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%B7%AF%E7%94%B1"><span class="nav-number">2.3.3.</span> <span class="nav-text">利用客户端导航的服务端路由</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%83%A8%E5%88%86%E6%B8%B2%E6%9F%93"><span class="nav-number">2.3.4.</span> <span class="nav-text">部分渲染</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%AB%98%E7%BA%A7%E8%B7%AF%E7%94%B1"><span class="nav-number">2.3.5.</span> <span class="nav-text">高级路由</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9"><span class="nav-number">2.3.6.</span> <span class="nav-text">修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%B7%AF%E7%94%B1%E4%B9%8B%E9%97%B4%E7%9A%84%E5%AF%BC%E8%88%AA%E6%96%B9%E6%B3%95"><span class="nav-number">2.3.7.</span> <span class="nav-text">路由之间的导航方法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Link"><span class="nav-number">2.3.7.1.</span> <span class="nav-text">Link</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#useRouter"><span class="nav-number">2.3.7.2.</span> <span class="nav-text">useRouter</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%80%E4%BA%9B%E6%A6%82%E5%BF%B5"><span class="nav-number">2.4.</span> <span class="nav-text">一些概念</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Server-Component-Vs-Client-Component"><span class="nav-number">2.4.1.</span> <span class="nav-text">Server Component Vs Client Component</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BB%84%E5%90%88%E4%BD%BF%E7%94%A8%E7%9A%84%E6%B8%B2%E6%9F%93%E6%B5%81%E7%A8%8B"><span class="nav-number">2.4.1.1.</span> <span class="nav-text">组合使用的渲染流程</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Reference"><span class="nav-number">3.</span> <span class="nav-text">Reference</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="ado" src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">ado</p>
  <div class="site-description" itemprop="description">me, robot.</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">94</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">60</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/adoontheway" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;adoontheway" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/adoontheway" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;adoontheway" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-github"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://cnblogs.com/adoontheway" title="Cnblogs → http:&#x2F;&#x2F;cnblogs.com&#x2F;adoontheway" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-cnblogs"></i>Cnblogs</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://legacy.gitbook.com/@adobeattheworld" title="Gitbook → https:&#x2F;&#x2F;legacy.gitbook.com&#x2F;@adobeattheworld" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-gitbook"></i>Gitbook</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">ado</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="external nofollow noopener noreferrer" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="external nofollow noopener noreferrer" target="_blank">NexT.Muse</a> 强力驱动
  </div>



        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//fastly.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  











<script>
document.querySelectorAll('.pdfobject-container').forEach(element => {
  let url = element.dataset.target;
  let pdfOpenParams = {
    navpanes : 0,
    toolbar  : 0,
    statusbar: 0,
    pagemode : 'thumbs',
    view     : 'FitH'
  };
  let pdfOpenFragment = '#' + Object.entries(pdfOpenParams).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&');
  let fullURL = `/lib/pdf/web/viewer.html?file=${encodeURIComponent(url)}${pdfOpenFragment}`;

  if (NexT.utils.supportsPDFs()) {
    element.innerHTML = `<embed class="pdfobject" src="${url + pdfOpenFragment}" type="application/pdf" style="height: ${element.dataset.height};">`;
  } else {
    element.innerHTML = `<iframe src="${fullURL}" style="height: ${element.dataset.height};" frameborder="0"></iframe>`;
  }
});
</script>


<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//unpkg.com/mermaid@8.14.0/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : '',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  

</body>
</html>
